def canteen_ordering_system():
    """食堂点餐系统主函数"""
    print("欢迎来到校园食堂点餐系统！")
    print("=" * 30)
    
    # 定义菜单及价格
    menu = {
        1: {"name": "红烧肉", "price": 18},
        2: {"name": "鱼香肉丝", "price": 15},
        3: {"name": "宫保鸡丁", "price": 16},
        4: {"name": "清炒时蔬", "price": 10},
        5: {"name": "番茄鸡蛋", "price": 12},
        6: {"name": "米饭", "price": 2},
        7: {"name": "紫菜蛋花汤", "price": 5}
    }
    
    # 显示菜单
    print("今日菜单：")
    for key, value in menu.items():
        print(f"{key}. {value['name']} - {value['price']}元")
    print("=" * 30)
    
    order = []  # 存储订单
    
    while True:
        # 选择菜品
        try:
            choice = int(input("请输入您要选择的菜品编号（输入0结束点餐）："))
            
            if choice == 0:
                if not order:  # 如果没有点任何菜品
                    print("您还没有点任何菜品，是否继续点餐？")
                    continue_order = input("继续点餐请按y，退出请按n：").lower()
                    if continue_order != 'y':
                        print("感谢您的光临，欢迎下次再来！")
                        return
                    else:
                        continue
                else:
                    break  # 结束点餐
            
            if choice not in menu:
                print("抱歉，没有这个菜品，请重新选择！")
                continue
            
            # 选择数量
            while True:
                try:
                    quantity = int(input(f"请输入{menu[choice]['name']}的数量："))
                    if quantity <= 0:
                        print("数量必须为正数，请重新输入！")
                    else:
                        break
                except ValueError:
                    print("请输入有效的数字！")
            
            # 添加到订单
            order.append({
                "name": menu[choice]['name'],
                "price": menu[choice]['price'],
                "quantity": quantity,
                "total": menu[choice]['price'] * quantity
            })
            print(f"已添加 {menu[choice]['name']} x {quantity} 到您的订单")
            
        except ValueError:
            print("请输入有效的数字！")
    
    # 显示订单详情
    print("\n您的订单详情：")
    print("-" * 30)
    total_amount = 0
    for item in order:
        print(f"{item['name']} x {item['quantity']} = {item['total']}元")
        total_amount += item['total']
    print("-" * 30)
    print(f"总计：{total_amount}元")
    
    # 支付流程
    print("\n请进行支付：")
    while True:
        try:
            payment = float(input(f"请支付{total_amount}元："))
            if payment < total_amount:
                print(f"金额不足，还需支付{total_amount - payment}元")
            elif payment == total_amount:
                print("支付成功！感谢您的光临，祝您用餐愉快！")
                break
            else:
                print(f"支付成功！找零{payment - total_amount}元。感谢您的光临，祝您用餐愉快！")
                break
        except ValueError:
            print("请输入有效的金额！")

# 运行点餐系统
if __name__ == "__main__":
    canteen_ordering_system()